package com.example.androidmqtt.Mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.androidmqtt.Entry.Message;
import com.example.androidmqtt.Vo.UserMessage;
import org.apache.ibatis.annotations.Select;

import java.util.ArrayList;

/**
 * @author: pjg
 * @time: 2022/10/1
 */
public interface MessageMapper extends BaseMapper<Message> {

    @Select("select message.news_id newsId,news.news_title newsTitle,news.news_content newsContent," +
            "user.user_name newsAuthor,user.user_avatar authorAvatar,department.department_name newsDepartment," +
            "news.news_appendix newsAppendix,message.isread isRead, DATE_FORMAT(publish_time,'%Y-%m-%d %H:%i') newsPublishTime " +
            "from message " +
            "left join news on message.news_id=news.news_id " +
            "left join user on news.news_author=user.user_id " +
            "left join department on news.news_department=department.department_id " +
            "where message.iscancel=0 " +
            "and news.news_author=user.user_id " +
            "and message.isread=0 "+
            "and message.user_id=#{userId} "+
            "order by news.publish_time desc, news_department")
    ArrayList<UserMessage> getReadMessage(Integer userId);
}
